const { ccclass, property } = cc._decorator;

import { app } from '../../app';
import { menu } from '../../decorator';
import { effecKeyEnum } from '../../executor';
import baseButtonTouch from './base/baseButtonTouch'

@ccclass
@menu(__filename)
export default class touchEffect extends baseButtonTouch {
    @property
    _effectName: string = effecKeyEnum[0] || '';
    @property({
        type: cc.Enum(effecKeyEnum)
    })
    get effectName(): number {
        const num = this._effectName ? effecKeyEnum[this._effectName] : 0;
        return typeof num === 'undefined' ? -1 : num;
    };
    set effectName(value) {
        this._effectName = effecKeyEnum[value];
    };

    onLoad() {
        const node = this.target || this.node;
        node.on(this.timeEvent, function () {
            effecKeyEnum[this.effectName] && app.manager.sound.playEffect({
                name: effecKeyEnum[this.effectName] as any
            });
        }, this);
    }
}
